<@app.html>
    <@app.head>
    <script>
        $(function () {
            $('#page_table').datagrid({
                fit: true,
                width: '100%',
                height: '100%',
                striped: true,
                pagination: true,
                url: "${contextPath}/security/basic/customer_foregift/page.htm",
                fitColumns: true,
                pageSize: 10,
                pageList: [10, 50, 100],
                idField: 'id',
                singleSelect: true,
                selectOnCheck: false,
                checkOnSelect: false,
                autoRowHeight: false,
                rowStyler: gridRowStyler,
                columns: [
                    [
                        {
                            title: '运营商',
                            align: 'center',
                            field: 'agentName',
                            width: 40
                        },
                        {
                            title: '代理商',
                            align: 'center',
                            field: 'agencyName',
                            width: 40
                        },
                        {
                            title: '押金(元)',
                            align: 'center',
                            field: 'forgiftMoney',
                            width: 20,
                            formatter: function(val) {
                                return Number(val / 100).toFixed(2);
                            }
                        },
                        {
                            title: '状态',
                            align: 'center',
                            field: 'status',
                            width: 20,
                            formatter: function (val) {
                                return val == 1 ? '启用' : '禁用'
                            }
                        },
                        {
                            title: '备注',
                            align: 'center',
                            field: 'notes',
                            width: 20
                        },
                        {
                            title: '修改时间',
                            align: 'center',
                            field: 'updateTime',
                            width: 60
                        },
                        {
                            title: '创建时间',
                            align: 'center',
                            field: 'createTime',
                            width: 60
                        },
                        {
                            title: '操作',
                            align: 'center',
                            field: 'id',
                            width: 50,
                            formatter: function (val, row) {
                                var html = '<a href="javascript:view(ID)">查看</a>';
                                <@app.has_oper oper_code='3_17_2'>
                                    html += ' <a href="javascript:edit(ID)">修改</a>'
                                </@app.has_oper>
                                <@app.has_oper oper_code='3_17_3'>
                                    html += ' <a href="javascript:remove(ID)">删除</a>'
                                </@app.has_oper>
                                return html.replace(/ID/g, row.id);
                            }
                        }
                    ]
                ],
                onLoadSuccess: function () {
                    $('#page_table').datagrid('clearChecked');
                    $('#page_table').datagrid('clearSelections');
                }
            });
        });

        function reload() {
            var datagrid = $('#page_table');
            datagrid.datagrid('reload');
        }
        <!-- 查询 -->
        function query() {
            var datagrid = $('#page_table');
            var forgiftMoney = $('#forgift_money').val();
            var agentId = null;
            var agencyId = null;
            <#-- 判断输入是否是数字 是否是空 -->
            if (forgiftMoney != "") {
                if (!isNaN(parseInt(forgiftMoney))) {
                   forgiftMoney = parseInt(forgiftMoney * 100);
                }else{
                $('#forgift_money').val(null);
                }
            }
            <#-- 判断搜索的选项(角色） -->
            if ($('#agent_id').length > 0) {
                agentId = $('#agent_id').combotree('getValue');
            }
            if ($('#agency_id').length > 0) {
                agencyId = $('#agency_id').combotree('getValue');
            }
            datagrid.datagrid('options').queryParams = {
                forgiftMoney: forgiftMoney,
                agentId: agentId,
                agencyId: agencyId
            };
            datagrid.datagrid('load');
        }
        function clears() {
            if ($('#agent_id').length > 0) {
                $('#agent_id').combotree('clear');
            }
            if ($('#agency_id').length > 0) {
                $('#agency_id').combotree('clear');
            }
            $('#forgift_money').val(null);
        }
        function add() {
            App.dialog.show({
                css: 'width:330px;height:360px;',
                title: '新建',
                href: "${contextPath}/security/basic/customer_foregift/add.htm",
                event: {
                    onClose: function () {
                        reload();
                    }
                }
            });
        }

        function remove(id) {
            $.messager.confirm('提示信息', '确认删除?', function (ok) {
                if (ok) {
                    $.post("${contextPath}/security/basic/customer_foregift/delete.htm?id=" + id, function (json) {
                        if (json.success == 1) {
                            $.messager.alert('提示消息', '操作成功', 'info');
                            reload();
                        } else {
                            $.messager.alert('提示消息', json.message, 'info');
                        }
                    }, 'json');
                }
            });
        }
        function edit(id) {
            App.dialog.show({
                css: 'width:380px;height:350px;',
                title: '修改',
                href: "${contextPath}/security/basic/customer_foregift/edit.htm?id=" + id,
                event: {
                    onClose: function () {
                        reload();
                    },
                    onLoad: function () {
                    }
                }
            });
        }

        function view(id) {
            App.dialog.show({
                css: 'width:350px;height:380px;',
                title: '查看',
                href: "${contextPath}/security/basic/customer_foregift/view.htm?id=" + id
            });
        }
    </script>
    </@app.head>
    <@app.body>
        <@app.container>
            <@app.banner/>
        <div class="main">
            <@app.menu/>
            <div class="content">
                <div class="panel search">
                    <table cellpadding="0" cellspacing="0" border="0">
                        <tr>
                            <#if Session['SESSION_KEY_USER'].type == Session['USER_TYPE_PLATFORM'].value>
                                <td align="right">运营商：</td>
                                <td>
                                    <input name="agentId" class="easyui-combotree" editable="false"
                                           style="width: 220px; height: 28px;" id="agent_id"
                                           data-options="url:'${contextPath}/security/basic/agent/tree.htm?',method:'get',onSelect: function(rec){
                                                        var url = '${contextPath}/security/hdw/agency/tree.htm?agentId='+rec.id;
                                                        $('#agency_id').combotree('reload', url);},
                                                        onChange:function(){
                                                        $('#agency_id').combotree('clear');}"/>
                                </td>
                                <td width="15"></td>
                            </#if>
                            <#if Session['SESSION_KEY_USER'].type != Session['USER_TYPE_AGENCY'].value>
                                <td align="right">代理商：</td>
                                <td>
                                    <input name="agencyId" class="easyui-combotree" editable="false" id="agency_id"
                                           data-options="<#if Session['SESSION_KEY_USER'].agentId??&&Session['SESSION_KEY_USER'].agentId!=0>url:'${contextPath}/security/hdw/agency/tree.htm?agentId=${Session['SESSION_KEY_USER'].agentId}',</#if>method:'get'"
                                           style="width: 220px; height: 28px;"/>
                                </td>
                            </#if>
                            <td align="right" width="60">押金(元)：</td>
                            <td><input type="text" class="text" id="forgift_money"/></td>
                            <td width="15"></td>
                            <td><button class="btn btn_yellow" onclick="query()">搜索</button></td>
                            <td width="15"></td>
                            <td><button class="btn btn_green" onclick="clears()">重置</button></td>
                        </tr>
                    </table>
                </div>
                <div class="panel grid_wrap">
                    <div class="toolbar clearfix">
                        <div class="float_right">
                            <@app.has_oper oper_code='3_17_4'>
                                <button class="btn btn_red" onclick="add()">新建</button>
                            </@app.has_oper>
                        </div>
                        <h3>客户押金设置</h3>
                    </div>
                    <div class="grid">
                        <table id="page_table"></table>
                    </div>
                </div>
            </div>
        </div>
        </@app.container>
    </@app.body>
</@app.html>

